package utils

import (
	"encoding/json"
	"strconv"
)

// ConvertToString
//
//	@Description: 将数据转换成字符串
//	@param data: 任意类型的数据
//	@return string
func ConvertToString(data interface{}) string {
	var value string
	switch data.(type) {
	case float64:
		value = strconv.FormatFloat(data.(float64), 'f', -1, 64)
	case float32:
		value = strconv.FormatFloat(float64(data.(float32)), 'f', -1, 64)
	case int:
		value = strconv.Itoa(data.(int))
	case uint:
		value = strconv.Itoa(int(data.(uint)))
	case int8:
		value = strconv.Itoa(int(data.(int8)))
	case uint8:
		value = strconv.Itoa(int(data.(uint8)))
	case int16:
		value = strconv.Itoa(int(data.(int16)))
	case uint16:
		value = strconv.Itoa(int(data.(uint16)))
	case int32:
		value = strconv.Itoa(int(data.(int32)))
	case uint32:
		value = strconv.Itoa(int(data.(uint32)))
	case int64:
		value = strconv.Itoa(int(data.(int64)))
	case uint64:
		value = strconv.Itoa(int(data.(uint64)))
	case string:
		value = data.(string)
	case []byte:
		value = string(data.([]byte))
	default:
		newData, _ := json.Marshal(data)
		value = string(newData)
	}
	return value
}
